package geographer;
import java.io.Serializable;
import java.util.Comparator;

/**
 * Project #3
 * CS 2334, 010
 * 03/07/2014
 * <P>
 * This class is a base class that has many of the other classes implement and inherit from.
 * It has many get/set methods. 
 * </P>
 * @version 2.0
 */
public abstract class GeographicRegion implements Comparable<String>, Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/*The name of the region*/
	private String name;
	
	/*The area of the region*/
	private String area;
	
	/*The pop. of the region*/
	private String population;
	
	
	/**
	 * The constructor for the class
	 * <P>
	 * Algorithm:<br>
	 * 1. Takes 3 inputs and creates an object out of them<br>
	 * </P> 
	 * @param	name	Name of the region
	 * @param	population	Population of the region
	 * @param	area	area of the region
	 * <dt><b>Conditions:</b>
	 * <dd>PRE -     Arguments are non-null
	 * <dd>POST -    The arguments are assigned appropriately
	 */
	public GeographicRegion(String name, String population ,String area) {
		this.name = name;
		this.population = population;
		this.area = area;
	}//end constructor
	
	public void edit(String name, String population ,String area) {
		this.name = name;
		this.population = population;
		this.area = area;
	}
	
	/**
	 * Getter for the <code>name</code> of the region
	 * <P>
	 * Algorithm:<br>
	 * 1. Return the name of the region<br>
	 * </P> 
	 * @return	name	Return the region's name
	 * <dt><b>Conditions:</b>
	 * <dd>POST -    The <code>name</code> of the region has been returned.
	 */
	public String getName(){
		return name;
	}//end getName
	

	/**
	 * Getter for the <code>area</code> of the region
	 * <P>
	 * Algorithm:<br>
	 * 1. Return the area of the region<br>
	 * </P> 
	 * @return	area	Return the region's area
	 * <dt><b>Conditions:</b>
	 * <dd>POST -    The <code>area</code> of the region has been returned.
	 */
	public String getArea(){
		return area;
	}//end getArea
	
	/**
	 * Abstract method to be overrided in the subclasses
	 * @return String The object's content in the form of a String.
	 */
	@Override
	public String toString(){
		return name;
	}
	
	/**
	 * Compares regions
	 * <P>
	 * Algorithm:<br>
	 * 1. Compares regions
	 * </P>
	 * @return	int	Int that compares region
	 * @param	r	GeographicRegion to compare to
	 * <dt><b>Conditions:</b>
	 * <dd>PRE -    r is non-null
	 * <dd>POST -    The objects are compared.
	 */
	@Override
	public int compareTo(String r){
		return this.name.toUpperCase().compareTo(r);
	}//end compareTo
	
	/**
	 * Getter for the <code>population</code> of the region
	 * <P>
	 * Algorithm:<br>
	 * 1. Return the population of the region<br>
	 * </P> 
	 * @return	population	Return the region's population
	 * <dt><b>Conditions:</b>
	 * <dd>POST -    The <code>population</code> of the region has been returned.
	 */
	public String getPopulation(){
		return population;
	}//end getPopulation
	
	/**
	 * Comparator for the populations of two regions
	 * <P>
	 * AlgorithmL<br>
	 * 1. Call compareTo to compare the populations as long values
	 * </P>
	 * @return	int	Int that contains the value of the population comparison
	 * <dt><b>Conditions:</b> 
	 * <dd>PRE -   Regions <code>r1</code> and <code>r2</code> are non-null
	 * <dd>POST -  The regions return and integer comparison value
	 */
	public static final Comparator<String> PO = new Comparator<String>(){
		@Override
		public int compare(String r1, String r2) {
			return Long.valueOf(GeoGrapher.data.getRegions().get(r2).getPopulation()).compareTo(Long.valueOf(GeoGrapher.data.getRegions().get(r1).getPopulation()));
		}
	};//end Comparator PO
	
	/**
	 * Comparator for the areas of two regions
	 * <P>
	 * AlgorithmL<br>
	 * 1. Call compareTo to compare the areas as long values
	 * </P>
	 * @return	int	Int that contains the value of the area comparison
	 * <dt><b>Conditions:</b> 
	 * <dd>PRE -   Regions <code>r1</code> and <code>r2</code> are non-null
	 * <dd>POST -  The regions return and integer comparison value
	 */
	public static final Comparator<String> AR = new Comparator<String>(){
		@Override
		public int compare(String r1, String r2) {
			return Long.valueOf(GeoGrapher.data.getRegions().get(r2).getArea()).compareTo(Long.valueOf(GeoGrapher.data.getRegions().get(r1).getArea()));
		}
	};//end Comparator AR

}//end GeographicRegion
